package com.java.exceptionLearn;

/**
 * @author Lenl
 * @create 2021-06-01 19:22
 *
 * 手动抛异常：throw
 *
 */
public class throwException {
    public static void main(String[] args) {
        Student s=new Student();
        try {
            s.regist(-1);
        } catch (Exception e) {
           // e.printStackTrace();
            System.out.println(e.getMessage());
        }
        System.out.println(s);
    }
}

class Student{
    private int id;
    public void regist(int id) throws Exception {
        if(id>0){
            this.id=id;
        }else{
            //System.out.println("数据非法");
            //手动抛出异常
            //throw new RuntimeException("您输入的数据非法！");//Runtime异常可以不用处理
            //throw new Exception("您输入的数据非法！");
            //抛出自定义异常
            throw new DIYException("您输入的数据非法");
        }
    }
}